﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace _2015.CEO
{
    /// <summary>
    /// Summary description for ProfilePicHandler
    /// </summary>
    public class ProfilePicHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.QueryString["uname"] != null)
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCSFINAL"].ConnectionString))
                {
                    string user_name = context.Request.QueryString["uname"];
                    DataTable dt = new DataTable();
                    //string query = "select p_pic from USERS where username = '"+user_name+"'";

                    //SqlDataAdapter sda = new SqlDataAdapter(query, con);
                    SqlCommand cmd = new SqlCommand("spImgName", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter username = new SqlParameter("@Username", user_name);
                    cmd.Parameters.Add(username);
                    con.Open();
                    SqlDataAdapter sda = new SqlDataAdapter();
                    sda.SelectCommand = cmd;

                    sda.Fill(dt);

                    //imgbtnYou.ImageUrl = "~/Data/" + Value;
                    //context.Response.BinaryWrite((Byte[])dt.Rows[0]["p_pic"]);
                    context.Response.BinaryWrite((Byte[])dt.Rows[0]["PROFILEPIC"]);
                    context.Response.End();
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}